// 这是制作科目袋卡片的函数

import { jsPDF } from "jspdf";

import { drawText, addFontToPdf, Rect, Point } from "./jspdf-helper.js";

/**
 * 绘制标签内容，不同的配置这个函数要对应修改
 * @param pdf pdf对象
 * @param label 标签尺寸
 * @param point 标签左上角位置
 * @param content 内容
 * @param withCutLine 是否要剪切边框
 * @returns
 */
export function drawBagLabel(
  pdf: jsPDF,
  label: Rect,
  point: Point,
  content: string[],
  withCutLine = true,
) {
  const { w, h } = label;
  const { x, y } = point;

  pdf.setLineWidth(1);
  pdf.setDrawColor("#ffc0cb");
  pdf.roundedRect(x + 2, y + 2, w - 4, h - 4, 4, 4).fill();

  addFontToPdf(pdf, "canger", "站酷仓耳渔阳体-W03.ttf");

  const fontOpt = {
    name: "canger",
    size: 16,
    color: "#00FF03",
  };

  const p1 = {
    x: x + w / 2,
    y: y + 10,
  };

  const p2 = {
    x: x + w / 2,
    y: y + 20,
  };

  const fontOpt2 = {
    name: "canger",
    size: 36,
    color: "#0005FF",
  };

  drawText(pdf, p1, content[1], "center", w, fontOpt);
  drawText(pdf, p2, content[3], "center", w, fontOpt2);

  if (withCutLine) {
    pdf.setLineWidth(0.1);
    pdf.setLineDashPattern([4, 2], 0);
    pdf.setDrawColor("#aaaaaa");
    pdf.rect(x, y, w, h).fill();
    pdf.setLineDashPattern([], 0);
  }

  return pdf;
}
